package cn.netbox.spring.handler;

import cn.netbox.spring.pojo.ZLQStudent;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Date;


@Aspect
@Component
public class ZLQAspect {
    @Around(value = "execution(public String *..register(..))")
    public Object myAround(ProceedingJoinPoint pjp) throws Throwable {
        Object result = pjp.proceed();
        Object[] args = pjp.getArgs();

        ZLQStudent student = new ZLQStudent(1,"tom","tom168","123");

        int i=1;
        for (Object arg : args) {
            if(arg==null){
                if(i==1){
                    result="id不能为空";
                }else if(i==2){
                    result= "名字不能为空";
                }else if(i==3){
                    result="账号";
                }else {
                    result="密码不能为空";
                }
            }
        }
        if(student.getEmile()!=args[2]){
            result="账号错误";
        }
        if(student.getPwd()!=args[3]){
            result="密码错误";
        }

        return result;
    }

    @Before(value = "execution(public String *..register(..))")
    public void myBefore(){
        System.out.println("时间"+ new Date());
    }
}
